Skip to content

Conversation

@adhikjoshi
Copy link

Currently only one Eloquent Casts is added AsDataObject

Adding remaining casts to make hypervel drop-in-replacement of Laravel

ArrayObject
AsArrayObject
AsCollection
Attribute
Json
AsStringable

https://github.com/laravel/framework/blob/12.x/src/Illuminate/Database/Eloquent/Casts/Attribute.php

@adhikjoshi
Copy link
Author

@albertcht Can you look into this?

@albertcht
Copy link
Member

Hi @adhikjoshi, thanks for your pull request! I will look into this PR by this weekend.

@albertcht albertcht added the feature New feature or request label Nov 7, 2025
@albertcht albertcht requested a review from Copilot November 7, 2025 17:57
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds database model casting support by introducing new casting classes and updating the Castable interface to support additional return types. The changes extend the framework's ability to handle JSON data and create custom attribute accessors/mutators for Eloquent models.

  • Extends the Castable interface to support CastsAttributes as a return type
  • Adds JSON encoding/decoding utility class with customizable encoders/decoders
  • Introduces new cast classes for collections and array objects
  • Adds Attribute class for defining custom accessors and mutators

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
src/foundation/src/Http/Contracts/Castable.php Updates interface to support CastsAttributes return type from Hyperf contract
src/core/src/Database/Eloquent/Casts/Json.php Adds JSON utility class with customizable encoding/decoding support
src/core/src/Database/Eloquent/Casts/Attribute.php Introduces attribute accessor/mutator class with caching support
src/core/src/Database/Eloquent/Casts/AsCollection.php Implements castable for collection types with optional mapping
src/core/src/Database/Eloquent/Casts/AsArrayObject.php Implements castable for ArrayObject with JSON serialization

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

* Get the name of the caster class to use when casting from / to this cast target.
*/
public static function castUsing(array $arguments = []): CastInputs|string;
public static function castUsing(array $arguments = []): CastInputs|CastsAttributes|string;
Copy link

Copilot AI Nov 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The CastInputs interface is referenced in the return type but not imported. Add use Hypervel\Foundation\Http\Contracts\CastInputs; at the top of the file to properly resolve this type.

Copilot uses AI. Check for mistakes.
@albertcht
Copy link
Member

Hi @adhikjoshi , there are Hyperf\Database\Model\Casts\ArrayObject::class and Hyperf\Database\Model\Casts\AsArrayObject::class in Hyperf framework.

I think you may try to submit this PR to Hyperf framework that Hypervel can benefit from it as well.

@adhikjoshi
Copy link
Author

Hi @adhikjoshi , there are Hyperf\Database\Model\Casts\ArrayObject::class and Hyperf\Database\Model\Casts\AsArrayObject::class in Hyperf framework.

I think you may try to submit this PR to Hyperf framework that Hypervel can benefit from it as well.

Good idea, adding PR there as well,

@adhikjoshi
Copy link
Author

I have fixed suggested changes, do review and feel free to merge it.

@albertcht
Copy link
Member

Hi @adhikjoshi , if this PR can be merged in Hyperf framework, and Hypervel can use these casters as well. So I intend to keep this PR open for a while. If Hyperf team rejected to merge your submitted PR then we can merge this one to Hypervel.

@albertcht albertcht changed the title Adding remaining Eloquent Casts Draft: migrate more Eloquent Casts Nov 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants